otvet=0
a=input()
if len(a)!=4:
    print("0")
else:
    def proverka(b):
        global otvet
        for i in range(2,b):
            if b%i==0:
                return()
                print(b)
        if b>otvet and b>1:
            otvet = b
    b=int(a[0:])
    proverka(b)
    b=int(a[0:3])
    proverka(b)
    b=int(a[1:])
    proverka(b)
    for i in range(3):
        b=int(a[i]+a[i+1])
        proverka(b)
    for i in range(4):
        b=int(a[i])
        proverka(b)
    print(otvet)
